package com.order.fegin;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Configuration
public class FeignBasicAuthConfiguration implements RequestInterceptor {
    private static final Logger log = LoggerFactory.getLogger(FeignBasicAuthConfiguration.class);

    public FeignBasicAuthConfiguration() {
    }

    public void apply(RequestTemplate requestTemplate) {
        try {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            requestTemplate.header(RootContext.KEY_XID, RootContext.getXID());
        } catch (Exception var4) {
            log.warn("warn:{}", var4.getMessage());
        }

    }
}
